Repository navigation
Add projection function for tree ensembles formulations - #551
Merged
Merged
Conversation
Solver tolerances and float32 rounding can leave the input of a solution outside the leaves it selects, so predict(x) need not match the output variable. - Add project_input() to the tree constraint classes. It returns the closest input inside the selected leaves, in the precision the regressor evaluates, or NaN rows if the leaves share no input. - Share the projection across frameworks; each wrapper stores its trees and declares its strict side and input precision. - Keep LightGBM thresholds in float64, as LightGBM compares them. - Call add_tree_ensemble_formulation directly from the sklearn ensembles and drop the helper that converted the trees again. - Document the parameters of _compute_leafs_bounds. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- Describe project_input() in Split Thresholds and Exactness of the user guide, with a short example. - Replace the hand-written leaf box helpers of the three tree ensemble notebooks with project_input(). - Show the leaves selected in each tree in the Tree Ensemble Formulations notebook. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Contributor
Author
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the tree-input projection change.
No open issues 🎉
What changed in this PR
Adds project_input() to tree constraints so users can check solutions when solver tolerances or input rounding cause predictions to differ from formulation outputs. This builds on the experimental tree-ensemble formulations introduced in #541.
Changes:
- Share precision-aware projection logic, returning NaN rows when selected leaves have no common input.
- Integrate projection across scikit-learn, XGBoost, and LightGBM; preserve LightGBM thresholds in float64 and simplify scikit-learn ensemble construction.
- Add cross-framework tests and replace duplicated notebook projection code with the public API.
| File | Description |
|---|---|
tests/tree_ensemble.py |
Add shared projection tests across formulations. |
tests/test_xgboost/test_project_input.py |
Apply projection tests to XGBoost. |
tests/test_sklearn/test_project_input.py |
Test scikit-learn projection and incompatible leaves. |
tests/test_lightgbm/test_project_input.py |
Apply projection tests to LightGBM. |
src/gurobi_ml/xgboost/xgboost_regressor.py |
Retain tree data and specify strict-left routing. |
src/gurobi_ml/sklearn/random_forest_regressor.py |
Retain tree data and use shared ensemble construction. |
src/gurobi_ml/sklearn/gradient_boosting_regressor.py |
Retain tree data and use shared ensemble construction. |
src/gurobi_ml/sklearn/decision_tree_regressor.py |
Remove the redundant ensemble-construction wrapper. |
src/gurobi_ml/modeling/decision_tree/decision_tree_model.py |
Expose project_input() through the shared tree accessor. |
src/gurobi_ml/modeling/decision_tree/_common.py |
Implement projection and rounding helpers; document leaf bounds. |
src/gurobi_ml/lightgbm/lgbm_regressor.py |
Preserve float64 thresholds and retain projection tree data. |
notebooks/tree-ensembles/Tree Ensemble Formulations.ipynb |
Use the projection API and display selected leaves. |
notebooks/tree-ensembles/Concrete and Wine Forest Optimization.ipynb |
Replace local projection helpers with project_input(). |
notebooks/tree-ensembles-merck/Drug Design with Tree Ensembles.ipynb |
Replace local projection helpers with project_input(). |
docs/source/user/mip-models.rst |
Explain projection usage, NaN results, and constraint caveats. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
project_input()to tree constraint classes. It returns the closest input consistent with the selected leaves, using the precision of the original regressor, orNaNif no feasible input can reach all selected leaves. This is an advanced technique used in some notebooks of #541.This addresses cases where solver tolerances or float32 rounding cause
predict(x)to differ from the formulation’s output.Changes